<?php
session_start();
//echo 'REMOTE'.$_SERVER['REMOTE_ADDR'];
//echo 'SERVER' .gethostbyname($_SERVER['SERVER_NAME']);

if((isset($_POST['link'])) and ($_SESSION['sessionCode'] == 'Th5aJ667HJH89-0SHI2jkhjsUGHJ7687SKJ')){



$request_xml = "<?xml version='1.0' encoding='utf-8'?>
<request>
    <id>12345</id>
<request>";


$datatopost = array(
    "linkToAdd" => $_POST['link'],
);

//Initialize handle and set options
$username = 'admin';
$password = 'guddes!pw';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://youswap.tv/scripts/controlScript.php');
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datatopost);

//Execute the request and also time the transaction ( optional )
//$start = array_sum(explode(' ', microtime()));
$result = curl_exec($ch);
//$stop = array_sum(explode(' ', microtime()));
//$totalTime = $stop - $start;

//Check for errors ( again optional )
if (curl_errno($ch)) {
    $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
} else {
    $returnCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    switch ($returnCode) {
        case 200:
            break;
        default:
            $result = 'HTTP ERROR -> ' . $returnCode;
            break;
    }
}

//Close the handle
curl_close($ch);

print $result;
//echo $totalTime;
}  else {
      print 'No Remote Access Allowed Or Wrong Parameters';

}

?>
